package com.wesley.prototype;

/**
 * <h1>概述</h1>
 * <p>详述</p>
 *
 * @Date: 2021/8/12
 */
public class PrototypeClient {
    public static void main(String[] args) throws CloneNotSupportedException {
//        Sheep sheep = new Sheep("小羊", "白色", 1);
//        Sheep sheep1  = (Sheep) sheep.clone();
//        System.out.println(sheep1.toString());
//        Sheep sheep2  = (Sheep) sheep.clone();
//        System.out.println(sheep2.toString());


        DeepClone deepClone = new DeepClone("深拷贝clone", new DeepCloneTarget("目标引用", "目标引用2"));
        System.out.println("deepClone target hashcode : " + deepClone.getDeepCloneTarget().hashCode());

        // 第一种方式， 使用默认的clone
//        DeepClone clone = (DeepClone) deepClone.clone();
//        System.out.println("clone target hashcode : " + clone.getDeepCloneTarget().hashCode());


        // 第二种方式
        DeepClone clone1 = (DeepClone) deepClone.deepClone();
        System.out.println("use deep clone Serializable target hashcode : " + clone1.getDeepCloneTarget().hashCode());
    }
}
